/*
 * @lc app=leetcode.cn id=198 lang=javascript
 *
 * [198] 打家劫舍
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var rob = function (nums) {
  if (nums.length <= 2) return Math.max(...nums);
  // 易错初始条件
  const curMax = [nums[0], Math.max(nums[0], nums[1])];
  for (let i = 2; i <= nums.length - 1; i++) {
    curMax[i] = Math.max(nums[i] + curMax[i - 2], curMax[i - 1]);
  }
  return curMax[nums.length - 1];
};
// @lc code=end
